<?php
/**
 * Created by PhpStorm.
 * User: CYF
 * Date: 2018/1/30
 * Time: 0:14
 * 教学方案
 */

namespace Home\Model;
use Think\Model\BaseModel;

class TeachingmethodModel extends BaseModel{
    protected $_link = array(
        'Teacher' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Teacher',
            'foreign_key' => 'tea_id',
            'mapping_fields' => 'tea_name',
            'as_fields' => 'tea_name'
        ),
        'Course' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Course',
            'foreign_key' => 'cou_id',
            'mapping_fields' => 'cou_name',
            'as_fields' => 'name'
        )
    );
    protected $_scope = array(
      'list' => array(
            'where' => array('cou_id'=>''),
            'field' => array('tme_id','tme_name','tea_id','cou_id','lan_name','tme_updatedate')
      ),
    );


    protected $_map = array(
        'id' => 'tme_id',
        'me_name' => 'tme_name',
        'teacher' => 'tea_name',
        'course' => 'name',
        'date' => 'tme_updatedate',
    );


    public function getTeachingMethodInfoListByAll(){
        $teachercourse = D('Teachercourse','Model');
        $tc_info = $teachercourse->where(array('tea_id'=>$this->tea_id))->field('cou_id')->select();
//            var_dump($tc_info);
        $con = array();
        foreach ($tc_info as $key => $value){
            $con[$key] = $value['cou_id'];
        }
        $course_id = array('in',$con);
        $result = $this->where(array('tea_id'=>$this->tea_id,'cou_id'=>$course_id))->select();

        if($result){
            return $result;
        }else{
            return array();
        }

    }

    public function getTeachingMethodListWithCourse($course_id){
        if ($course_id == 0){

            $teachercourse = D('Teachercourse','Model');
            $tc_info = $teachercourse->where(array('tea_id'=>$this->tea_id))->field('cou_id')->select();
//            var_dump($tc_info);
            $con = array();
            foreach ($tc_info as $key => $value){
                $con[$key] = $value['cou_id'];
            }
            $course_id = array('in',$con);
        }
        $result = $this ->scope('list',array('where'=>array('cou_id'=>$course_id,'tea_id'=>$this->tea_id)))->relation(true) -> select();

        if($result){
            return $result;
        }else{
            return array();
        }

    }
}